package cn.mactoon.utils;

import cn.mactoon.config.SmsConfig;
import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;


@Configuration
public class SmsUtils {
    @Autowired
    private SmsConfig smsConfig;

    public boolean SmsSend(String to,String templateId,String[] datas) {

        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(smsConfig.getServerIp(),smsConfig.getServerPort());
        sdk.setAccount(smsConfig.getAccountSId(),smsConfig.getAccountToken());
        sdk.setAppId(smsConfig.getAppId());
        sdk.setBodyType(BodyType.Type_JSON);
        HashMap<String, Object> result = sdk.sendTemplateSMS(to, templateId, datas);
        if ("000000".equals(result.get("statusCode"))) {
           return true;
        }
            return false;

    }

}
